<title>图书搜索</title>

<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a><cite>图书馆</cite></a>
        <a><cite>图书搜索</cite></a>
    </div>
</div>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">图书搜索</div>
                <div class="layui-card-body">
                    <table class="layui-hide" id="test-table-page" lay-filter="test"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="lineBar">
    <a class="layui-btn layui-btn-xs" lay-event="detail">借阅详情</a>
</script>
<script>
    layui.use(['jquery', 'table'], function(){
        var $ = layui.$, form = layui.form,
            table = layui.table, admin = layui.admin,
            view = layui.view;
        var type = "any";
        var keyword = "";
        var tablelns = null;
        var width = window.screen.availWidth > 420 ? 420 : window.screen.availWidth;
        admin.popup({
            title: "搜索图书",
            area: [width + "px", "450px"],
            id: "LAY-popup-user-edit",
            success: function(layero, index) {
                view(this.id).render("menu/library/searchform").done(function() {
                    form.on("submit(LAY-user-back-submit)", function(data) {
                        layer.close(index);
                        var field = data.field;
                        type = field.type;
                        keyword = field.keyword;
                        if (keyword.length == 0) {
                            return;
                        } else {
                            tablelns = table.render({
                                elem: '#test-table-page'
                                ,url: "/uclass/library/search"
                                ,method: 'post'
                                ,where: {type:type, keyword:keyword}
                                ,contentType: 'application/json'
                                ,cols: [[
                                    {field:'title', minWidth:200, title: '书名', align: 'center'}
                                    ,{field:'author', minWidth:100, title:'作者', align:'center'}
                                    ,{field:'publisher', minWidth:180, title: '出版社', align: 'center'}
                                    ,{field:'pubYear', minWidth:80, title:'年份', align:'center'}
                                    ,{align:'center', minWidth:150, title:'操作', toolbar:'#lineBar'}
                                ]]
                                ,page: true
                                ,parseData: function(res) {
                                    return {
                                        "status": res.status,
                                        "message": res.message,
                                        "total": res.data.total,
                                        "list": res.data.content
                                    };
                                }
                                ,response: {
                                    statusName: 'status'
                                    ,statusCode: 200
                                    ,msgName: 'message'
                                    ,countName: 'total'
                                    ,dataName: 'list'
                                }
                            });
                        }
                    })
                })
            }
        });
        table.on('tool(test)', function (obj) {
            switch (obj.event) {
                case 'detail':
                    admin.popup({
                        title: "图书借阅详情",
                        area: [window.screen.availWidth + "px", window.screen.availHeight * 0.9 + "px"],
                        id: "LAY-popup-user-edit",
                        success: function(layero, index) {
                            view(this.id).render("menu/library/lenddetail").done(function () {
                                table.render({
                                    elem: '#lenddetail-table-page'
                                    ,url: "/uclass/library/storeinfo"
                                    ,where: {marcRecNo: obj.data.marcRecNo}
                                    ,cols: [[
                                        {field:'bookNum', minWidth:100, title: '索书号', align: 'center'}
                                        ,{field:'address', minWidth:300, title:'位置', align:'left'}
                                        ,{field:'status', minWidth:80, title: '状态', align: 'center'}
                                    ]]
                                    ,parseData: function(res) {
                                        return {
                                            "status": res.status,
                                            "message": res.message,
                                            "list": res.data
                                        };
                                    }
                                    ,response: {
                                        statusName: 'status'
                                        ,statusCode: 200
                                        ,msgName: 'message'
                                        ,countName: 'total'
                                        ,dataName: 'list'
                                    }
                                });
                            });
                        }
                    });
                    break;
            }
        });
    });
</script>